package com.situ.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.situ.mall.pojo.Category;
import com.situ.mall.mapper.CategoryMapper;
import com.situ.mall.pojo.vo.CategoryCountVO;
import com.situ.mall.service.ICategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Gao
 * @since 2025-06-17
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> selectTopCategory() {
        // select * from category where parent_id=0;
        QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id", 0);
        List<Category> list = categoryMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public List<Category> selectSecondCategoryByTopCategoryId(Integer id) {
        QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id", id);
        List<Category> list = categoryMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public List<CategoryCountVO> selectCategoryCount() {
        return categoryMapper.selectCategoryCount();
    }
}
